package com.jingsheng.jingshengcity.mvp.ui.activity.address;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;

import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.UiUtils;
import com.jingsheng.jingshengcity.R;
import com.jingsheng.jingshengcity.di.component.DaggerAddressListComponent;
import com.jingsheng.jingshengcity.di.module.AddressListModule;
import com.jingsheng.jingshengcity.mvp.contract.AddressListContract;
import com.jingsheng.jingshengcity.mvp.presenter.AddressListPresenter;
import com.jingsheng.jingshengcity.mvp.ui.adapter.AddressListActivityAdapter;
import com.jingsheng.jingshengcity.widgets.decoration.GridItemDecoration;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

import static com.jess.arms.utils.Preconditions.checkNotNull;

/**
 * Created by Administrator on 2017/5/19.
 */

public class AddressListActivity extends BaseActivity<AddressListPresenter> implements AddressListContract.View, View.OnClickListener {

    @NonNull
    @BindView(R.id.rv_list)
    RecyclerView mRecyclerView;
    @NonNull
    @BindView(R.id.btn_create_address)
    Button mBtnCreate;

    private List<String> mList = new ArrayList<>();

    @Override
    public void setupActivityComponent(AppComponent appComponent) {
        DaggerAddressListComponent
                .builder()
                .appComponent(appComponent)
                .addressListModule(new AddressListModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView() {
        setTitle("收货地址列表");
        return R.layout.activity_address_list;
    }

    @Override
    public void initData() {

        mList.add("1");
        mList.add("1");
        mList.add("1");

        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        AddressListActivityAdapter mAddressListActivityAdapter = new AddressListActivityAdapter(R.layout.adapter_address_list_item, mList);
        mAddressListActivityAdapter.openLoadAnimation();
        mRecyclerView.addItemDecoration(new GridItemDecoration(this, R.drawable.list_divider_5));
        mRecyclerView.setAdapter(mAddressListActivityAdapter);

        initEvent();
    }

    private void initEvent() {
        mBtnCreate.setOnClickListener(this);
    }


    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        UiUtils.SnackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        UiUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_create_address:
                toCreate();
                break;
        }
    }

    private void toCreate() {
        Intent intent = new Intent(this, CreateAddressActivity.class);
        startActivity(intent);
    }
}